package se.topshelf.golftracker.core.service;

import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import se.topshelf.golftracker.core.domain.BaseEntity;
import se.topshelf.golftracker.core.repository.BaseRepository;

import java.util.List;

/**
 *
 */
@Transactional
public abstract class BaseServiceImpl<T extends BaseEntity> implements BaseService<T> {
    public T get(String id) {
        return getBaseRepository().get(id);
    }

    public <S extends BaseEntity> S get(Class<S> baseEntityClass, String id) {
        return getBaseRepository().get(baseEntityClass, id);
    }

    public <S extends BaseEntity> void delete(S entity) {
        getBaseRepository().delete(entity);
    }

    public <S extends BaseEntity> void saveOrUpdate(S entity) {
        getBaseRepository().saveOrUpdate(entity);
    }

    public List<T> findAll() {
        return getBaseRepository().findAll();
    }

    public void clearSession() {
        getBaseRepository().clear();

    }

    public <S extends BaseEntity> S merge(S entity) {
        return getBaseRepository().merge(entity);
    }

    public <S extends BaseEntity> List<S> findAll(Class<S> baseEntityClass) {
        return getBaseRepository().findAll(baseEntityClass);
    }

    abstract BaseRepository<T> getBaseRepository();
}


